var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    but: "加 入",
    tab_index: 0,
    array: ['美国', '中国', '巴西', '日本'],
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    var openid = app.globalData.openid;
    app.ihttpGet("https://www.58zltc.com/api.php/Quan/notice/openid/" + openid, function (res) {
      that.setData({
        list: res.data
      })
    })
  },
  bindChange: function (e) {
    var list = this.data.list;
    var k = e.detail.value;
    var circle = list[k]
    this.setData({
      circle: circle
    })
  },
  bindinput:function(e){
    console.log(e)
    this.setData({
      notice:e.detail.value
    })
  },
  formSubmit: function (e) {
    // console.log(e.detail.value);
    wx.showLoading({
      title: '加载中',
      mask: true
    })
    let that = this;
    var post_data = e.detail.value;
    var data = this.data;
    post_data.notice = data.notice;
    post_data.circle = data.circle;
    that.ihttpPost(post_data);
  },
  ihttpPost: function (post_data) {
    app.ihttpPost("https://www.58zltc.com/api.php/Quan/addnotice", post_data, function (res) {
      if (res.data.err_code === 400) {
        wx.showToast({
          title: res.data.err_msg,
        })
      }  else {
        wx.showToast({
          title: res.data.err_msg,
        })
        setTimeout(function () {
          wx.navigateBack({})
        }, 1500)
      }
    })
  },
  backto: function (e) {
    wx.navigateBack({})
  },
  onShareAppMessage: function () {
  },
  changeTab: function (e) {
    this.setData({
      tab_index: e.currentTarget.dataset.tab_index
    })
  }
})